<template>
    <el-dialog :visible.sync="visible" :title="title">
      <el-form label-width="100px">
        <el-form-item label="仓库名">
          <el-input v-model="data.name"/>
        </el-form-item>
        <el-form-item label="仓库地址">
          <el-input v-model="data.address"/>
        </el-form-item>
        <el-form-item label="仓库说明">
          <el-input type="textarea" v-model="data.info"/>
        </el-form-item>
        <el-form-item label="仓库排序">
          <el-input-number v-model="data.sort" :min="1" :max="255"/>
        </el-form-item>
        <div style="margin-top: 10px; text-align: center">
          <el-button type="primary" icon="el-icon-edit" @click="save">
            保存
          </el-button>
        </div>
      </el-form>
    </el-dialog>
</template>

<script>
    export default {
        name: "storageDialog",
      data(){
          return {
            visible: false,
            title:"",
            data:{
              ...this.initData()
            }
          }
      },
      methods:{
          initData(){
            return {
              name:"",
              info:"",
              address:"",
              sort: 0
            }
          },
        reset(){
          this.data = this.initData()
        },
        show(item){
            this.reset()
            if(!item){
              this.title = "新增仓库"
            } else {
              this.title = "编辑仓库"
            }
          this.visible = true
        },
        save(){
          this.$http({
            url: this.$http.adornUrl('/sys/storage/saveStock'),
            method: 'post',
            data: this.$http.adornData(
              this.data
            )
          }).then(({ data }) => {
            this.$emit("ok")
            this.visible = false
          })
        }
      }
    }
</script>

<style scoped>

</style>
